import React, { Component } from 'react'
import { InputItem, Toast, Button } from 'antd-mobile'
import { createForm } from 'rc-form'
// let inputPattern = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9]{2,})+$|^1[34578]\d{9}$/
let inputPattern = ''
class LoginForm extends Component {
    submit = () => {
        this.props.form.validateFields((error, value) => {
            if (!error) {
                value.type = "psd";
                console.log(value)
                this.props.loginHandle(value)
            } else {
                if (error['verifyText']) {
                    Toast.info('请输入正确的手机号或邮箱', 2)
                } else {
                    Toast.info('输入错误', 2)
                }
            }
        })
    }
    render() {
        const { getFieldProps } = this.props.form;
        return (
            <>
                <InputItem
                    {...getFieldProps('verifyText', {
                        rules: [{ required: true, pattern: inputPattern }]
                    })}
                    placeholder="手机号/邮箱"
                    ref={el => (this.inputRef = el)}
                />
                <InputItem
                    {...getFieldProps('password', {
                        rules: [{ required: true }]
                    })}
                    type="password"
                    placeholder="密码"
                    ref={el => (this.inputRef = el)}
                />
                <Button type="primary" onClick={this.submit} style={{ 'margin': ".2rem 0" }}>  密码登录 </Button>
            </>
        )
    }
}
export default createForm()(LoginForm)
